package com.fengba.nanzhi.tabbar04.wz;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.fengba.nanzhi.fengba.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Text;

/**
 * Created by 89311 on 2018/4/24.
 */

public class BillAdapter extends RecyclerView.Adapter<BillAdapter.LinerViewHolder> {
    private Context context;
    private JSONArray jsonArray;
    private JSONObject jsonObject;

    public BillAdapter(Context context,JSONArray jsonArray) {
        this.context = context;
        this.jsonArray = jsonArray;
    }

    @Override
    public BillAdapter.LinerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new BillAdapter.LinerViewHolder(LayoutInflater.from(context).inflate(R.layout.wz_bill_item_view,parent,false));
    }

    @Override
    public void onBindViewHolder(BillAdapter.LinerViewHolder holder, int position) {
        try {
             jsonObject = (JSONObject) jsonArray.get(position);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        try {
            if(jsonObject.get("type").toString().equals("0")){
                holder.billImg.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.img_0073));
                holder.Identification.setText("+");
                holder.BillExplain.setText("收款-收款手续费:"+jsonObject.get("service_charge").toString());
            }else{
                holder.billImg.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.img_0087));
                holder.Identification.setText("-");
                holder.BillExplain.setText("提现-提现手续费:"+ jsonObject.get("service_charge").toString());
            }
            holder.BillNumber.setText(jsonObject.get("trade_money").toString());

            String time = jsonObject.get("createtime").toString();
            String time1 = time.substring(0, 10);
            holder.BillTime.setText(time1);

            holder.BillFinalNumber.setText(jsonObject.get("actual_money").toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getItemCount() {
        if(jsonArray!=null){
            return jsonArray.length();
        }else{
            return 0;
        }
    }

    class LinerViewHolder extends RecyclerView.ViewHolder{
        private ImageView billImg;
        private TextView Identification,BillNumber,BillExplain,BillTime,BillFinalNumber;
        public LinerViewHolder(View itemView) {
            super(itemView);
            billImg = itemView.findViewById(R.id.billImg);
            Identification = itemView.findViewById(R.id.Identification);
            BillNumber = itemView.findViewById(R.id.BillNumber);
            BillExplain = itemView.findViewById(R.id.BillExplain);
            BillTime = itemView.findViewById(R.id.BillTime);
            BillFinalNumber = itemView.findViewById(R.id.BillFinalNumber);

        }
    }
}
